<template>
  <div class="fullMain">
    <x-header :left-options="{backText: '',showBack: true}" >
      加群认证
    </x-header>
    <div v-transfer-dom>
      <alert v-model="isShowAlert" :content="alertText"></alert>
    </div>
    <div style="height:20px"/>
    <div class="mainbBg" style="margin-top:40%">
      <div class="saveDiv">
        <button type="button" class="affirmBtn specialBtn mB" @click="accept">
          <i class="fa fa-check"></i>
          <span>同意加入</span>
        </button>
        <button type="button" class="affirmBtn specialBtn mB" @click="reject">
          <i class="fa fa-times" style="color:red"></i>
          <span style="color:red">拒绝加入</span>
        </button>
      </div>
    </div>
  </div>
</template>
<script>
import {XHeader} from 'vux'
import group from 'api/group'
import user from 'api/user'
import common from 'utilMethods/common.js'

export default {
  name: 'G_group_new_member_verify',
  data() {
    return {
      paramsInUrl: {},
      alertText: '', // 验证提示框的文本
      isShowAlert: false, // 是否显示验证提示框
    }
  },
  components: {
    XHeader,
  },
  mounted() {
    this.getParamsFromUrl()
  },
  methods: {
    back() {
      WeixinJSBridge.call("closeWindow")
    },
    showAlert(alertText){
      this.isShowAlert = true
      this.alertText = alertText
    },
    closeTip(){
      this.isShowAlert = false
      this.alertText = ''
    },
    async getParamsFromUrl() {
      let url = decodeURI(window.location.href)
      this.paramsInUrl.userId = Number(common.getValFromUrl(url, 'userId'))
      this.paramsInUrl.groupId = Number(common.getValFromUrl(url, 'groupId'))
    },
    async accept() {
      const result = await group.getVerifyAgree(this.paramsInUrl)
      if (result.code === 1) {
        // this.showAlert('加入成功,将跳转到相应群页面...')
        // const resultOfGetGroupInfo = await group.getGroupInfoByGroupId(this.paramsInUrl.groupId)
        // let groupPresent = resultOfGetGroupInfo.data
        // this.$store.commit('recordGroupPresent', groupPresent)
        // setTimeout(this.$router.push({name: 'G_group_member'}), 2000)
        this.showAlert('加入成功,即将退出易享小秘...')
        setTimeout(() => {
          WeixinJSBridge.call('closeWindow')
        }, 2000)
      } else {
        this.showAlert(result.message)
        setTimeout(() => {
          WeixinJSBridge.call('closeWindow')
        }, 2000)
      }
    },
    async reject() {
      const result = await group.getVerifyDisagree(this.paramsInUrl)
      if (result.code === 1) {
        this.showAlert('拒绝成功,即将退出易享小秘...')
        setTimeout(() => {
          WeixinJSBridge.call('closeWindow')
        }, 2000)
      } else {
        this.showAlert(result.message)
        setTimeout(() => {
          WeixinJSBridge.call('closeWindow')
        }, 2000)
      }
    }
  },
}
</script>
